package com.rceeslca.common.exception;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * Exception工具类
 * @author rceeslca
 */
public class ExceptionUtils {

    /**
     * 获取异常信息
     * @param exception 异常
     */
    public static String getErrorStackTrace(Exception exception){

        StringWriter sw = null;
        PrintWriter pw = null;

        try{
            sw = new StringWriter();
            pw = new PrintWriter(sw,true);
            exception.printStackTrace(pw);
        }finally{
            try{
                if(pw!=null){
                    pw.close();
                }
            }catch(Exception e){

            }
            try{
                if(sw!=null){
                    sw.close();
                }
            }catch(IOException e){

            }
        }

        return sw.toString();
    }

}
